function loadss() {

    //节点
    const tbodyEle = document.querySelector('tbody')
    let arr = []
    /**
     * 数据引入
     */
    function productData() {
        $.ajax({
            type: "get",
            url: "http://47.107.88.7:8089/api/list_page",
            data: {
                pageNo: $('#current-code').html(),
                pageSize: 5
            },
            dataType: "json",
            success: function (data) {
                let allcodes = data.resultInfo.totalNum
                $('#all-code').html(allcodes)
                let arrList = data.resultInfo.list
                for (let i = 0; i < arrList.length; i++) {
                    arr.push(arrList[i])
                }
                rander()
                checks()
            }
        });
    }
    productData()
    /**
     * 渲染到页面
     */
    function rander() {
        let str = `<tr>
            <th><input type="checkbox" class="checkbox-all">全选</th>
            <th>头像</th>
            <th>访客编号</th>
            <th>昵称</th>
            <th>年龄</th>
            <th>目的</th>
            <th>学历</th>
            <th>公司</th>
            <th colspan="2">操作</th>
            </tr>`
        for (let i = 0; i < arr.length; i++) {
            str += `<tr>
                    <td> <input type="checkbox" class="checkbox-item"></td>
                    <td class="imgs"><img src="http://m.imeitou.com/uploads/allimg/2020081710/gllzrxprcao-lp.jpg"></td>
                    <td>${arr[i].uid}</td>
                    <td>${arr[i].username}</td>
                    <td>${arr[i].age}</td>
                    <td>${arr[i].visitgoal}</td>
                    <td>${arr[i].education}</td>
                    <td>${arr[i].company}</td>
                    <td><a href="#" class="delete">删除</a> </td>
                    <td><a href="#" class="edio">编辑</a></td>
                </tr>`
        }
        tbodyEle.innerHTML = str
        deleteProduct()
        replaceInfo()
    }
    /**
     * 删除商品
     */
    function deleteProduct() {
        $('.delete').click(function () {
            $.ajax({
                type: "get",
                url: "http://47.107.88.7:8089/api/delete",
                data: {
                    uid: $(this).parent().parent().children().first().next().next().html()
                },
                dataType: "json",
                success: function (data) {
                    if (data.resultCode == 1) {
                        arr = []
                        productData()
                        $('.infos').css('display', 'block')
                        setTimeout("$('.infos').css('display','none')", 2000)
                    }
                }
            });
        })
    }
}
loadss()
/**
 * 页码显示
 */
function showPages() {
    let codes = $('#current-code').html()
    $('#reduce').click(function () {
        if (codes <= 1) {
            return codes
        }
        $('#current-code').text(--codes)
        loadss()
        return codes
    })
    $('#push').click(function () {
        $.ajax({
            type: "get",
            url: "http://47.107.88.7:8089/api/list_page",
            data: {
                pageNo: $('#current-code').html(),
                pageSize: 5
            },
            dataType: "json",
            success: function (data) {
                let allcodes = data.resultInfo.totalNum
                $('#all-code').html(allcodes)
                if (codes >= allcodes) {
                    return codes
                }
                $('#current-code').text(++codes)
                loadss()
                return codes
            }
        });


    })
}
showPages()

/**
 * 修改访客信息
 */
let radioList = document.querySelectorAll('input[type="radio"]')



function replaceInfo() {
    $('.edio').click(function () {
        $('#id').val('')

        let psObj = $(this).offset()
        $('.forms').css('position', 'absolute')
        // $('.forms').css('left', psObj.left - 700 + 'px')
        $('.forms').css('left', '35%')
        // $('.forms').css('top', psObj.top - 100 + 'px')
        $('.forms').css('top', '20%')
        console.log(psObj)
        $('.forms').fadeIn(1000)

        // 默认自动点击提交
        $("#submit").trigger("click")
    })
}
/**
 * 提交修改信息
 */
subInfo()

function subInfo() {
    $('#submit').click(function () {
        // id非空
        if ($('#id').next()) {
            $('#id').next().remove()
        }
        if ($('#id').val() == '') {
            $('#id').parent().append($('<p>').html('请输入要修改的访客编号').addClass('action'))
            return
        }
        $.ajax({
            type: "post",
            url: "http://47.107.88.7:8089/api/update",
            data: {
                uid: $('#id').val(),
                username: $('#username').val(), // 姓名
                age: $('#age').val(), // 年龄
                sex: function () {
                    for (let j = 0; j < radioList.length; j++) {
                        if (radioList[j].checked) {
                            let sex1 = $(radioList[j]).attr('class')
                            // console.log(sex1)
                            return sex1
                        }
                    }
                }, // 性别 男0 女1
                visitgoal: $('#visitgoal').val(), // 来访目的
                visittime: new Date(), // 到访时间,\
                education: $('#education').val(), // 学历
                company: $('#company').val(), // 单位
            },
            dataType: "json",
            success: function (data) {
                if (data.resultCode == 1) {
                    loadss()
                    alert('ok')
                    $('#id').val('')
                    $('.forms').css('display', 'none')
                }
            }
        });
    })
}
/**
 * 关闭修改页面
 */
function close() {
    $('#close').click(function () {
        $('.forms').fadeOut(1000)
      })
  }
  close()